<template>
  <div class="register">
    <navstxt msg="This is an register page" />
    <div class="box-item">
      <div class="box-list">
        <input type="text" placeholder="用户名" v-model="todos[0].user">
      </div>
      <div class="box-list">
        <input type="password" placeholder="密码" v-model="todos[0].password">
      </div>
      <div class="box-list">
        <input type="password" placeholder="重复密码" v-model="todos[0].repassword">
      </div>
      <div class="box-list">
        <input type="button" value="注册" @click="regposts()">
      </div>
    </div>
  </div>
</template>

<script>
  // @ is an alias to /src
  import navstxt from "@/components/nav.vue";
  import qs from 'qs'
  export default {
    name: "reg",
    components: {
      navstxt
    },
    data () {
      return {
        content : '',
        todos: [
          {
            user : '',
            password: '',
            repassword: '',
          }
        ]
      }
    },
    methods: {
      regposts () {
        this.$axios.post('/api/reg',qs.stringify({reg:this.todos}, { indices: false }))
                .then(res=>{
                  if(res.data.code==1){
                    alert(res.data.message);
                    window.location.href = '/';
                  }
                  if(!res.data.code){
                    alert(res.data.message);
                    window.location.href = '/';
                  }
                })
                .catch(err=>{
                  console.log(err);
                })
      }
    }
  };
</script>